﻿using System.Data.Entity.ModelConfiguration.Conventions;
using LM.Negocio;
using LM.Negocio.Objetos;
using LM.Repositorios.Maps;
using System.Data.Entity;

namespace LM.Repositorios
{
    public class Contexto : DbContext
    {
        public Contexto()
            : base( "LM" )
        {
            // Database.SetInitializer( new CreateDatabaseIfNotExists<Contexto>() );
            Database.SetInitializer( new DropCreateDatabaseIfModelChanges<Contexto>() );
        }

        protected override void OnModelCreating( DbModelBuilder modelBuilder )
        {
            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();

            modelBuilder.Configurations.Add( new MarcaMap() );
            modelBuilder.Configurations.Add( new GaragemMap() );
            modelBuilder.Configurations.Add( new VagaMap() );
            modelBuilder.Configurations.Add( new EnderecoMap() );
            modelBuilder.Configurations.Add( new OperadorMap() );
            modelBuilder.Configurations.Add( new TelefoneMap() );
            modelBuilder.Configurations.Add( new ClienteMap() );
            modelBuilder.Configurations.Add( new DependenteMap() );
            modelBuilder.Configurations.Add( new TipoDeVeiculoMap() );
            modelBuilder.Configurations.Add( new TabelaPrecoMap() );
            modelBuilder.Configurations.Add( new ModeloMap() );
           // modelBuilder.Configurations.Add( new LocacaoMap() );
           // modelBuilder.Configurations.Add( new ItemTabelaDePrecoMap() );
            modelBuilder.Configurations.Add( new VeiculoMap() );
        }

        public DbSet<Marca> Marca { get; set; }
        public DbSet<TabelaDePreco> TabelaPreco { get; set; }
        public DbSet<ItemTabelaDePreco> ItemTabelaPreco { get; set; }
        public DbSet<Garagem> Garagem { get; set; }
        public DbSet<Vaga> Vaga { get; set; }
        public DbSet<Cliente> Cliente { get; set; }
        public DbSet<Endereco> Endereco { get; set; }
        public DbSet<Telefone> Telefone { get; set; }
        public DbSet<Dependente> Dependente { get; set; }
        public DbSet<Operador> Operador { get; set; }
        public DbSet<TipoDeVeiculo> TipoDeVeiculo { get; set; }
        public DbSet<Modelo> Modelo { get; set; }
        public DbSet<Veiculo> Veiculo { get; set; }
        public DbSet<Locacao> Locacao { get; set; }
    }
}
